#include <iostream>
#include <fstream>
#include <string>
#include <limits>
#include <vector>
#include <deque>
#include <map>

using namespace std;

struct Edge {
    int cur;
    int max;
};

enum Color {
    C_WHITE,
    C_BLACK
};

void BFS(int start, vector<vector<Edge> >& adjMatrix, vector<int>& piArray, int& cfpMin) {
    piArray.assign(adjMatrix.size(), -1);
    deque<int> q;
    vector<int> cfMin(adjMatrix.size(), numeric_limits<int>::max());
    vector<Color> color(adjMatrix.size(), C_WHITE);

    color[start] = C_BLACK;
    q.push_back(start);
    
    int front;
    while(!q.empty()){
        front = q.front();
        q.pop_front();

        color[front] = C_BLACK;
        for (int i = 0; i < adjMatrix.size(); ++i) {
            if ((adjMatrix[front][i].max - adjMatrix[front][i].cur) > 0 && color[i]==C_WHITE) {
                q.push_back(i);
                piArray[i] = front;
                color[i] = C_BLACK;
                if (adjMatrix[front][i].max - adjMatrix[front][i].cur < cfMin[front])  {
                    cfMin[i] = adjMatrix[front][i].max - adjMatrix[front][i].cur;
                } else  cfMin[i] = cfMin[front];
            }
        }
    }
    cfpMin = cfMin[adjMatrix.size()-1];
}

void fordFulkerson(vector<vector<Edge> >& adjMatrix) {
    vector<int> parent;
    int cfpMin;
    BFS(0, adjMatrix, parent, cfpMin);
    while (*parent.rbegin() != -1) { //проверяем, можем ли добраться до последней фиктивной вершины. (По алгоритму из Кормена действие продолжается до тех пор, пока существует путь от начальной вершины к конечной)
        for (int i = parent.size() - 1; parent[i] != -1; i = parent[i]) { 
            adjMatrix[parent[i]][i].cur += cfpMin;
            adjMatrix[i][parent[i]].cur = -adjMatrix[parent[i]][i].cur;
        }
        BFS(0, adjMatrix, parent, cfpMin);
    }
}

void showRightCubes(vector<vector<Edge> >& adjMatrix, string& wordToFind, int amountOfCubes, map<char, pair<int, int> >& requiredLetters) {
    vector<bool> cubeHasBeenPrinted(amountOfCubes, false);
    for (size_t i = 0; i < wordToFind.size(); ++i) {
        for (size_t j = 1; j <= amountOfCubes; ++j) {
            if (adjMatrix[j][(amountOfCubes + 1) + requiredLetters[wordToFind[i]].second - 1].cur > 0 && !cubeHasBeenPrinted[j - 1]) {
                cout<<j<<" ";
                cubeHasBeenPrinted[j - 1] = true; 
                break;
            }
        }
    }
    cout<<endl;
}

void readFile(vector<vector<Edge> >& adjMatrix, string& wordToFind, int& amountOfCubes, map<char, pair<int, int> >& requiredLetters) {
    
    fstream input("in.txt", fstream::in);
    if(!input.is_open()) {
        cout<<"Error: something wrong with input file!"<<endl;
        exit(1);
    }

    input>>wordToFind;
    int amountOfUniqueLetters = 0;
    for (int i = 0; i < wordToFind.size(); ++i) {
        ++requiredLetters[wordToFind[i]].first;
        if (requiredLetters[wordToFind[i]].second==0) {
            requiredLetters[wordToFind[i]].second = ++amountOfUniqueLetters;
        }
    }

    input>>amountOfCubes;
    adjMatrix.resize(amountOfCubes + amountOfUniqueLetters + 2);
    for (size_t i = 0; i < adjMatrix.size(); ++i) adjMatrix[i].resize(amountOfCubes + amountOfUniqueLetters + 2);
    
    string cubeLetters;
    for (size_t i = 1; i <= amountOfCubes; ++i) {
        adjMatrix[0][i].max = 1;
        
        input>>cubeLetters;

        for (size_t j = 0; j < 6; ++j) {
            if (requiredLetters[cubeLetters[j]].first > 0) {
                ++adjMatrix[i][requiredLetters[cubeLetters[j]].second - 1 + amountOfCubes + 1].max;
                adjMatrix[(amountOfCubes + 1) + (requiredLetters[cubeLetters[j]].second - 1)][amountOfCubes + amountOfUniqueLetters + 1].max =
                    requiredLetters[cubeLetters[j]].first;
            }
        }
    }

    input.close();
}

int main() {
    string wordToFind;
    int amountOfCubes;
    vector<vector<Edge> > adjMatrix;
    map<char, pair<int, int> > requiredLetters;
 
    readFile(adjMatrix, wordToFind, amountOfCubes, requiredLetters);

    fordFulkerson(adjMatrix);

    for (size_t i = 0; i < wordToFind.size(); ++i) {
        if (adjMatrix[(amountOfCubes + 1) + (requiredLetters[wordToFind[i]].second - 1)][adjMatrix.size() - 1].cur !=
            requiredLetters[wordToFind[i]].first) {
            cout<<"NO"<<endl;
            system("pause");
            return 0;
        }
    }

    cout<<"YES"<<endl;
    showRightCubes(adjMatrix, wordToFind, amountOfCubes, requiredLetters);    

    system("pause");
    return 0;
}